<?php
/**
 * BootAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using BootAdmin.
 *
 * @Author G.r<root@BootAdmin.com>
 */

declare (strict_types=1);

namespace app\admin\controller;

use app\admin\Base;
use app\admin\logic\LoginLogic;
use app\admin\validate\LoginValidate;

/**
 * 登录控制器
 */
class Login extends Base
{
    // 无需登录的方法
    public array $notNeedLogin = ['account'];

    public array $notNeedRight = ['logout'];

    protected LoginLogic $logic;

    protected LoginValidate $validate;

    /**
     * 初始化
     */
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->logic = new LoginLogic();
        $this->validate = new LoginValidate();
    }

    /**
     * 登录
     */
    public function account()
    {
        $params = $this->validate->post()->goCheck();
        return $this->data($this->logic->login($params));
    }

    /**
     * 注销登录
     */
    public function logout()
    {
        $this->validate->get()->go();
        $this->logic->logout($this->request->token);
        return $this->success();
    }
}